#!/usr/bin/env bash

# Create a new directory and enter it
function mkd() {
    mkdir -p "$@" && cd "$_";
}

# Determine size of a file or total size of a directory
function fs() {
    if du -b /dev/null > /dev/null 2>&1; then
        local arg=-sbh;
    else
        local arg=-sh;
    fi
    if [[ -n "$@" ]]; then
        du $arg -- "$@";
    else
        du $arg ./*;
    fi;
}

# Use Git’s colored diff when available
hash git &>/dev/null;
if [ $? -eq 0 ]; then
    function diff() {
        git diff --no-index --color-words "$@";
    }
fi;

function grepx() {
    grep -nr $1 .
}

# send file use scp
function send() {
    if [ $# -lt 2 ]; then
        echo "usage: send file... target"
        return -1
    fi

    ip_addr=0
    arg_list=""
    declare -i i=1
    for arg in $@; do
        if [ ${i} -eq $# ]; then
            ip_addr=${arg}
        else
            arg_list+="${arg} "
        fi
        i+=1
    done

    scp -r ${arg_list} root@172.16.0.${ip_addr}:
}
